/***********************************************************************************
 * 文件名： LHS114TC-IG01.c
 * 作者： 刘言
 * 版本： 1
 * 说明：
 *      LHS114TC-IG01 初始化函数
 * 修改记录：
 * 	2024/07/22: 初版。 刘言。
***********************************************************************************/
#include "st7789v.h"
#include "lcd_config.h"
#include "polsys.h"


// 函数名称固定，给 Lcd_Init 调用
// 初始化函数可能依据不同的屏幕其内容要做修改，建议参考屏幕厂商例程
void Lcd_ChipInit()
{
    _Lcd_PortInit();
    _Lcd_SetRstLevel(0);
    _Lcd_Delayms(10);
    _Lcd_SetRstLevel(1);
    _Lcd_Delayms(120);
    // _Lcd_Delayms(10);

    WriteOneByteCmd(_CMD_SOFT_RESET);
    _Lcd_Delayms(5);
    WriteOneByteCmd(_CMD_SLEEP_OUT);
    _Lcd_Delayms(5);

    WriteOneByteCmd(_CMD_MEM_ACCESS_CTRL);
    WriteOneByteData(0X00);// 0X00 竖屏，0X60横屏
    WriteOneByteCmd(_CMD_SET_IF_FMT);
    WriteOneByteData(0x05);
    WriteOneByteCmd(_CMD_DIS_INVERSION_ON); // 反向显示 

    WriteOneByteCmd(_CMD_PORCH_CTRL);
    WriteOneByteData(0X05);     //0C
    WriteOneByteData(0X05);     //0C
    WriteOneByteData(0X00);     
    WriteOneByteData(0X33);
    WriteOneByteData(0X33);
    WriteOneByteCmd(_CMD_GATE_CTRL1);
    WriteOneByteData(0X23);    //VGH=13V, VGL=-10.4V 
    WriteOneByteCmd(_CMD_GATE_CTRL2);
    WriteOneByteData(0X22);
    WriteOneByteData(0X00);
    WriteOneByteData(0X00);


    WriteOneByteCmd(_CMD_SET_VCOM);
    WriteOneByteData(0X22); 
    WriteOneByteCmd(_CMD_LCM_CTRL);
    WriteOneByteData(0X2C);
    WriteOneByteCmd(_CMD_EN_VDV_VRH);
    WriteOneByteData(0X01);
    WriteOneByteCmd(_CMD_SET_VRH); 
    WriteOneByteData(0x13); // 12 // GVDD=3.95V
    WriteOneByteCmd(_CMD_SET_VDV); 
    WriteOneByteData(0x20); 
    WriteOneByteCmd(_CMD_FR_CTRL2); 
    WriteOneByteData(0x0F); 
    WriteOneByteCmd(_CMD_POWER_CTRL1); 
    WriteOneByteData(0xa4); 
    WriteOneByteData(0xa1); 

    WriteOneByteCmd(0XD6); 
    WriteOneByteData(0xA1); 

    // WriteOneByteCmd(_CMD_POWER_CTRL2);
    // WriteOneByteData(0x03);
    // WriteOneByteCmd(_CMD_EQ_TIME_CTRL);
    // WriteOneByteData(0x0d);
    // WriteOneByteData(0x12);
    // WriteOneByteData(0x00);
    //----------------------------------------------------------------------------------------------------// 
    WriteOneByteCmd(_CMD_PV_GAM_CTRL);       //gamma setting 
    WriteOneByteData(0x70); 
    WriteOneByteData(0x06); 
    WriteOneByteData(0x0C); 
    WriteOneByteData(0x08); 
    WriteOneByteData(0x09); 
    WriteOneByteData(0x27); 
    WriteOneByteData(0x2E); 
    WriteOneByteData(0x34); 
    WriteOneByteData(0x46); 
    WriteOneByteData(0x37); 
    WriteOneByteData(0x13); 
    WriteOneByteData(0x13); 
    WriteOneByteData(0x25); 
    WriteOneByteData(0x2A);
    
    WriteOneByteCmd(_CMD_NV_GAM_CTRL); 
    WriteOneByteData(0x70); 
    WriteOneByteData(0x04); 
    WriteOneByteData(0x08); 
    WriteOneByteData(0x09); 
    WriteOneByteData(0x07); 
    WriteOneByteData(0x03); 
    WriteOneByteData(0x2C); 
    WriteOneByteData(0x42); 
    WriteOneByteData(0x42); 
    WriteOneByteData(0x38); 
    WriteOneByteData(0x14); 
    WriteOneByteData(0x14); 
    WriteOneByteData(0x27); 
    WriteOneByteData(0x2C); 

    // WriteOneByteCmd(_CMD_DIS_ON);       //display on 
    // _Lcd_Delayms(120);
    WriteOneByteCmd(_CMD_WRITE_MEM);
}
